package cn.est.config;

import cn.est.interceptor.ExceptionInterceptor;
import cn.est.interceptor.LoginInterceptor;
import cn.est.interceptor.ValidateParamInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器配置类
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    /**
     * 自定义拦截器-登录权限校验
     */
    @Resource
    private LoginInterceptor loginInterceptor;
    /**
     * 自定义拦截器-统一异常处理
     */
    @Resource
    private ExceptionInterceptor exceptionInterceptor;
    /**
     * 自定义拦截器-参数校验
     */
    @Resource
    private ValidateParamInterceptor validateParamInterceptor;

    /*
    添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/api/**");
        registry.addInterceptor(validateParamInterceptor).addPathPatterns("/api/**");

        registry.addInterceptor(exceptionInterceptor).addPathPatterns("/**");
    }
}
